import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('@/views/home/index.vue'),
    },
    {
      path: '/login',
      name: 'Login',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('@/views/login/index.vue'),
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/views/register/index.vue'),
    },
    {
      path: '/archives',
      name: 'archives',
      component: () => import('@/views/archives/index.vue'),
    },
    {
      path: '/message',
      name: 'message',
      component: () => import('@/views/message/index.vue'),
    },
    {
      path: '/friends',
      name: 'friends',
      component: () => import('@/views/friends/index.vue'),
    },
    {
      path: '/music',
      name: 'music',
      component: () => import('@/views/music/index.vue'),
    },
    {
      path: '/music/selected-playlists',
      name: 'SelectedPlaylists',
      component: () => import('@/views/music/components/selected-playlists.vue'),
    },
    {
      path: '/music/popular-playlists',
      name: 'PopularPlaylists',
      component: () => import('@/views/music/components/popular-playlists.vue'),
    },
    {
      path: '/music/new-songs',
      name: 'new-songs',
      component: () => import('@/views/music/components/new-songs.vue'),
    },
    {
      path: '/music/recommendation-mv',
      name: 'RecommendationMV',
      component: () => import('@/views/music/components/recommendation-mv.vue'),
    },
    {
      path: '/music/deepseek',
      name: 'DeepSeek',
      component: () => import('@/views/music/components/deepseek.vue'),
    },
    {
      path: '/music/tools',
      name: 'Tools',
      component: () => import('@/views/music/components/tools.vue'),
    },
    {
      path: '/music/settings',
      name: 'Settings',
      component: () => import('@/views/music/components/settings.vue'),
    },
    {
      path: '/music/theme',
      name: 'Theme',
      component: () => import('@/views/music/components/theme.vue'),
    },
    {
      path: '/album',
      name: 'album',
      component: () => import('@/views/album/index.vue'),
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('@/views/about/index.vue'),
    },
    {
      path: '/timeline',
      name: 'Timeline',
      component: () => import('@/views/archives/timeline/index.vue')
    },
    {
      path: '/tags',
      name: 'Tags',
      component: () => import('@/views/archives/tags/index.vue')
    },
    {
      path: '/categories',
      name: 'Categories',
      component: () => import('@/views/archives/categories/index.vue')
    }
  ],
})

// 添加导航守卫
router.beforeEach((to, from, next) => {
  // 检查完整的目标URL
  const fullPath = to.fullPath.slice(1) // 移除开头的斜杠
  if (fullPath.startsWith('http://') || fullPath.startsWith('https://')) {
    window.open(fullPath, '_blank')
    next(false) // 阻止路由导航
  } else {
    next() // 继续正常的路由导航
  }
})

export default router
